﻿using GalaSoft.MvvmLight.Command;
using LibNiconico.NiconicoApi.Mylist;
using NicoView.ViewModel.Message;

using NicoView.Model.Service.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace NicoView.ViewModel
{
    public class NicoViewVideoAddConsoleViewModel:NicoViewVideoInfoNicoViewViewModelBase
    {
        private NicoVideoConsoleEventArgs videoAddEventArgs;

        public NicoViewVideoAddConsoleViewModel():base()
        {
            
        }

        public NicoViewVideoAddConsoleViewModel(NicoVideoConsoleEventArgs videoAddEventArgs)
            : base(videoAddEventArgs.Title, videoAddEventArgs.ThumbnailUrl, videoAddEventArgs.Id)
        {
            this.mylistItems.AddRange(videoAddEventArgs.MylistItems);

            if (this.MylistItems.Count() > 0)
            {
                this.AddTarget = this.MylistItems.First();
            }

            this.videoAddEventArgs = videoAddEventArgs;
        }



        public NicoMylistItem AddTarget
        {

            get;

            set;

        }

        private List<NicoMylistItem> mylistItems = new List<NicoMylistItem>();
        public IEnumerable<NicoMylistItem> MylistItems
        {
            get
            {
                return mylistItems;
            }
        }

        private ICommand addCommand { get; set; }


        public ICommand AddCommand
        {
            get
            {
                if (this.addCommand == null)
                {
                    this.addCommand = new RelayCommand(async() =>
                    {
                        if (videoAddEventArgs != null)
                        {
                            this.videoAddEventArgs.AddTarget = this.AddTarget;
                            var result = await this.videoAddEventArgs.AddExecuteAsync();

                            if (result.Value)
                            {
                                this.MessengerInstance.Send(new NicoViewResultShowMessage(result.Message));
                            }
                        }
                    });

                }

                return this.addCommand;
            }

        }

    }
}
